/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			session.h
  \date			Feb 2012
  \author		TNick

  \brief		Contains the definition for Session class


*//*


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read COPYING and README files in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __SESSION_INC__
#define __SESSION_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<QList>

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

namespace	PgSave	{

class	IPgSave;

}

namespace	PgScr		{

class	Module;

/**
*	@brief	class that groups run-time data for a session
*/
class Session				{

	//
	//
	//
	//
	/*  DEFINITIONS    ----------------------------------------------------- */

	/*  DEFINITIONS    ===================================================== */
	//
	//
	//
	//
	/*  DATA    ------------------------------------------------------------ */


public:

	/**
	*	@brief pointer to default session; there must always be a default session
	*
	*	A default session is created on PgS_Initialise and the default one is
	*	deleted when PgS_Terminate is called
	*/
	static Session *				def_ss;


private:


	/**
	*	@brief the list of loaded modules
	*/
	QList<Module* >		module_list_;


	/**
	*	@brief the list of core modules
	*/
	QList<Module* >		core_list_;


	/**
	*	@brief the default module; new elements without explicit parent gets added here
	*/
	Module				def_md_;


	/*  DATA    ============================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */

public:


	/**
	*	@brief	constructor;
	*/
	Session			( void );


	/**
	*	@brief	destructor;
	*/
	virtual				~Session		( void );


	/**
	*	@brief	append a module to the internal list
	*/
	inline void			appendModule	( Module * new_it )
	{ module_list_.append( new_it ); }


	/**
	*	@brief	append a module to the internal list
	*/
	inline void			removeModule	( Module * new_it )
	{
		Q_ASSERT( ! core_list_.contains( new_it ) );
		module_list_.removeOne( new_it );
	}


	/**
	*	@brief	append a module to the internal list
	*/
	inline int			moduleCount		( void )
	{ return module_list_.count(); }


	/**
	*	@brief	gets the module at index i
	*/
	inline Module*		module			( int i )
	{
		if ( i >= module_list_.count() ) return NULL;
		return module_list_.at( i );
	}


	/**
	*	@brief	gets the index of the module
	*/
	inline int			module			( Module * p_m )
	{	return module_list_.indexOf( p_m );   	}


	/**
	*	@brief	gets the module with specified name
	*/
	Module*				module			( QString & s_name );


	/**
	*	@brief	 tell if a module is one of the core module
	*/
	inline bool			isCoreModule	( Module * md )
	{ return core_list_.contains( md ); }


	/**
	*	@brief	 makes a module core module
	*/
	inline void			addCoreModule	( Module * md )
	{ Q_ASSERT( module_list_.contains( md ) ); core_list_.append( md ); }


	/**
	*	@brief	 removes a module from core module list
	*/
	inline void			remCoreModule	( Module * md )
	{ Q_ASSERT( core_list_.contains( md ) ); core_list_.removeOne( md ); }


	/**
	*	@brief	 removes a module from core module list
	*/
	inline Module *		sessionDefModule	( void )
	{ return &def_md_; }



	/**
	*	@brief	saves the content of this session
	*/
	void				save			 (
			QString				s_name,
			PgSave::IPgSave &	targ_i
			);



	/**
	*	@brief	creates a new session and loads its content
	*/
	static Session *	load			(
			QString				s_name,
			PgSave::IPgSave &	targ_i
			);



	/**
	*	@brief	gets the default module for default session
	*/
	inline static Module*		defModule		( void )
	{ return &def_ss->def_md_; }



	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
	//

};	/*	class Session	*/

/*  CLASS    =============================================================== */
//
//
//
//

#ifdef	PGSCRIPT_TESTS
void				Session_Tests					(
		int & performed, int & succeded );
#endif

}	//	namespace	PgScr

#endif // __SESSION_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
